﻿using Mengsk.ProxyDelivery.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace Mengsk.ProxyDelivery.Print.Domain.DeliveryNumberGenerator
{
    class ZJSDeliveryNumberGenerator : DeliveryNumberGenerator
    {
        public override bool AcceptDeliveryCompany(string arg)
        {
            return arg.Contains("宅急送");
        }

        public override string GenenrateNext(string deliveryNumberAlgorithm, string current)
        {
            if (current.Length != 10)
            {
                throw new Exception("宅急送运单号为长度为10");
            }

            try
            {
                int d1 = int.Parse(current.Substring(0, 3));
                int d2 = int.Parse(current.Substring(3, 3));
                int d3 = int.Parse(current.Substring(6, 3));
                int d4 = int.Parse(current.Substring(9, 1));

                d4 = (++d4) % 7;
                d2 += (++d3) / 1000;
                d1 += (d2 + 1) / 1000;

                d3 = d3 % 1000;
                d2 = d2 % 1000;

                string ret = string.Format("{0:d3}{1:d3}{2:d3}{3}", d1, d2, d3, d4);
                if (ret.Length != 10)
                {
                    MessageBox.Show("产生的运单号不正确定");
                }
                return ret;
            }
            catch (Exception ex)
            {
                throw new Exception("参数：" + current + " 不合法，无法成功下一个单号" + Environment.NewLine + ex.Message);
            }
        }

        public override string GenenrateOnline(Order order, string wuliuId)
        {
            throw new NotImplementedException();
        }

        public override void CancelOnline(WuliuNumber wuliuNumber)
        {
            throw new NotImplementedException();
        }

        public override string GenenrateWuliuId(params string[] orderIds)
        {
            throw new NotImplementedException();
        }
    }
}
